package com.liuheng.manager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liuheng.manager.service.ProductSpecService;
import com.liuheng.spzx.model.entity.product.ProductSpec;
import com.liuheng.spzx.model.vo.common.Result;
import com.liuheng.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {
    @Autowired
    private ProductSpecService productSpecService;
    @GetMapping("/{page}/{limit}")
    public Result<Page<ProductSpec>> findByPage(@PathVariable int page,@PathVariable int limit){
        Page<ProductSpec> specPage = new Page<>(page, limit);
        Page<ProductSpec> page1 = productSpecService.page(specPage);
        return Result.build(page1, ResultCodeEnum.SUCCESS);
    }
    @PutMapping("/updateById")
    public Result updateProductSpec(@RequestBody ProductSpec productSpec){
        productSpecService.updateById(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/deleteById/{id}")
    public Result deleteProductById(@PathVariable Long id){
        productSpecService.removeById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    public Result saveProductSpec(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/findAll")
    public Result findAllProductSpec(){
        List<ProductSpec> list = productSpecService.list();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }
}
